import { combineReducers, configureStore } from '@reduxjs/toolkit';

import languageReducer from './language/language-reducer';
import { actionLog } from './middleware/action-log';
import { productDetailSlice } from './product-detail/slice';
import { productSearchSlice } from './product-search/slice';
import recommendProductsReducer from './recommend-products/recommend-products-reducer';
import { userSlice } from './user/slice';

const rootReducer = combineReducers({
  language: languageReducer,
  recommendProducts: recommendProductsReducer,
  productDetail: productDetailSlice.reducer,
  productSearch: productSearchSlice.reducer,
  user: userSlice.reducer
});
const store = configureStore({
  reducer: rootReducer,
  middleware: (getDefaultMiddleware) => [...getDefaultMiddleware(), actionLog] as any,
  devTools: true
});

export type RootState = ReturnType<typeof store.getState>;
export default store;
